package com.huawei.appgallery.horizontalcard.api.card;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.RecyclerView.n;
import androidx.recyclerview.widget.RecyclerView.s;
import com.huawei.appgallery.foundation.card.base.normal.bean.NormalCardBean;
import com.huawei.appgallery.foundation.store.bean.detail.DetailResponse;
import com.huawei.appgallery.foundation.ui.css.CSSRule;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import com.huawei.appgallery.horizontalcard.api.bean.BaseHorizontalModuleCardBean;
import com.huawei.appgallery.horizontalcard.api.view.BounceHorizontalRecyclerView;
import com.huawei.appgallery.horizontalcard.api.view.BounceHorizontalRecyclerView.c;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appgallery.serverreqkit.api.listener.IServerCallBack;
import com.huawei.appmarket.service.exposure.bean.ExposureDetail;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import o.ccz;
import o.cfw;
import o.cgz;
import o.chy;
import o.chz;
import o.cib;
import o.clk;
import o.cll;
import o.clm;
import o.clp;
import o.clr;
import o.cls;
import o.cvt;
import o.BaseRequest;
import o.dgm;
import o.ContentManager;
import o.SomeTimerTask;
import o.eiy;
import o.CollectCheck;
import o.MinimumFactory;
import o.evt;

public abstract class BaseHorizontalModuleCard<T extends NormalCardBean> extends cgz implements o.clr.b {
    protected int ʻ;
    protected View ʼ;
    private T ʽ;
    public LinearLayoutManager ˊ;
    protected chy ˋ;
    protected BounceHorizontalRecyclerView ˎ;
    protected clr ˏ;
    private long ˏॱ;
    private int ͺ;
    public clp<T> ॱ;
    private b ॱˊ;
    private BaseHorizontalModuleCardBean<T> ॱॱ;
    protected cls ᐝ = new cls();

    class a implements c {
        final /* synthetic */ BaseHorizontalModuleCard ˏ;

        private a(BaseHorizontalModuleCard baseHorizontalModuleCard) {
            this.ˏ = baseHorizontalModuleCard;
        }

        public boolean ˏ() {
            if (this.ˏ.ॱ == null || this.ˏ.ॱ.ॱ() == null || !this.ˏ.ॱ.ॱॱ()) {
                return false;
            }
            this.ˏ.ॱ.ॱ().add(this.ˏ.ʽ);
            this.ˏ.ˏ.ॱ(this.ˏ.ॱ.ॱ().size() - 1);
            this.ˏ.ˋॱ();
            return true;
        }
    }

    class b extends SomeTimerTask {
        final /* synthetic */ BaseHorizontalModuleCard ˊ;
        private boolean ˎ;
        private int ॱ;

        private b(BaseHorizontalModuleCard baseHorizontalModuleCard, boolean z, int i) {
            this.ˊ = baseHorizontalModuleCard;
            this.ˎ = false;
            this.ॱ = i;
            this.ˎ = z;
        }

        public int[] getVisibleImtePos() {
            int[] iArr = new int[]{-1, -1};
            if (this.ˊ.ˊ != null) {
                try {
                    iArr[0] = this.ˊ.ˊ.ॱˊ();
                    iArr[1] = this.ˊ.ˊ.ʻॱ();
                } catch (Exception e) {
                    cll.ˎ.ˏ("BaseHorizontalModuleCard", "findFirstVisibleItemPosition error:" + e.toString());
                }
            }
            return iArr;
        }

        public View ˏ(int i) {
            View view = null;
            if (this.ˊ.ˊ != null) {
                try {
                    view = this.ˊ.ˊ.ˋ(i);
                } catch (Exception e) {
                    cll.ˎ.ˏ("BaseHorizontalModuleCard", "getViewByPosition error:" + e.toString());
                }
            }
            return view;
        }

        public List<ExposureDetail> ˏ(int i, int i2) {
            Collection ˊॱ;
            Object obj = evt.ˊ(this.ˊ.ˎ) >= 50 ? 1 : null;
            ArrayList arrayList = new ArrayList();
            ArrayList arrayList2 = new ArrayList();
            if (this.ˎ) {
                ˊॱ = this.ˊ.ˊॱ();
            } else {
                ˊॱ = null;
            }
            if (obj == null && CollectCheck.isEmpty(ˊॱ)) {
                return arrayList;
            }
            String valueOf;
            if (obj != null) {
                Collection ˎ = this.ˊ.ˎ(i, i2);
                if (!CollectCheck.isEmpty(ˎ)) {
                    arrayList2.addAll(ˎ);
                }
            }
            if (!CollectCheck.isEmpty(ˊॱ)) {
                arrayList2.addAll(ˊॱ);
            }
            ExposureDetail exposureDetail = new ExposureDetail();
            exposureDetail.ˎ(arrayList2);
            if (this.ˊ.ॱ != null) {
                valueOf = String.valueOf(this.ˊ.ॱ.ˎ());
            } else {
                valueOf = null;
            }
            exposureDetail.ॱ(valueOf);
            exposureDetail.ˏ(System.currentTimeMillis());
            arrayList.add(exposureDetail);
            return arrayList;
        }

        public long ˊ() {
            return this.ˊ.ˏॱ;
        }

        public int ˋ() {
            return this.ॱ;
        }

        public boolean ˎ(int i) {
            return super.ˎ(i);
        }
    }

    class d implements IServerCallBack {
        final /* synthetic */ BaseHorizontalModuleCard ˎ;

        d(BaseHorizontalModuleCard baseHorizontalModuleCard) {
            this.ˎ = baseHorizontalModuleCard;
        }

        public void prePostResult(BaseRequest o_cvu, ResponseBean responseBean) {
        }

        public void notifyResult(BaseRequest o_cvu, ResponseBean responseBean) {
            this.ˎ.ॱ.ॱ().remove(this.ˎ.ॱ.ॱ().size() - 1);
            this.ˎ.ˏ.ˋ(this.ˎ.ॱ.ॱ().size());
            if ((responseBean instanceof DetailResponse) && responseBean.getResponseCode() == 0) {
                DetailResponse detailResponse = (DetailResponse) responseBean;
                if (detailResponse.getRtnCode_() == 0) {
                    this.ˎ.ॱ.ˏ(detailResponse);
                    this.ˎ.ॱॱ.ʻˋ().clear();
                    this.ˎ.ॱॱ.ʻˋ().addAll(this.ˎ.ॱ.ॱ());
                    this.ˎ.ॱॱ.ॱ(this.ˎ.ॱ.ॱॱ());
                    this.ˎ.ॱॱ.ॱˊ(this.ˎ.ॱ.ˊ());
                    List<NormalCardBean> ॱ = this.ˎ.ॱ.ॱ();
                    if (!CollectCheck.isEmpty(ॱ)) {
                        for (NormalCardBean ˋˋ : ॱ) {
                            ˋˋ.ˋˋ(this.ˎ.ॱॱ.ॱˉ());
                        }
                    }
                }
            }
            this.ˎ.ˏ.ˊ();
            this.ˎ.ʼ().setLoading(false);
        }
    }

    protected abstract void ˎ();

    public BaseHorizontalModuleCard(Context context) {
        super(context);
        ˎ();
    }

    protected int ˋ() {
        return 1;
    }

    public cgz ˏ(View view) {
        ʽ(view);
        ˋ(view);
        ॱ(view);
        return this;
    }

    public void ˋ(View view) {
        this.ʿ = null;
        this.ʼ = null;
        this.ˎ = null;
    }

    protected boolean ʽ() {
        return false;
    }

    protected void ˋ(androidx.recyclerview.widget.RecyclerView.a aVar, RecyclerView recyclerView) {
    }

    protected void ʻ() {
        this.ˏ = new clr(this.ʼॱ, this.ॱ, this.ᐝ, this, ʽ());
    }

    private void ॱ(View view) {
        if (this.ॱ == null) {
            this.ॱ = new clp();
        }
        if (this.ˎ == null) {
            cll.ˎ.ˊ("BaseHorizontalModuleCard", "recyclerView == null");
            return;
        }
        this.ॱ.ˊ(ˋ());
        ʻ();
        ˋ(this.ˏ, this.ˎ);
        this.ˏ.ʼ(dgm.ˎ((Activity) view.getContext()));
        this.ˊ = new LinearLayoutManager(view.getContext(), 0, false);
        this.ˎ.setLayoutManager(this.ˊ);
        if (MinimumFactory.getBoolValue(ContentManager.getInstant().getContext())) {
            this.ˎ.setLayoutDirection(0);
            this.ˊ.ˊ(true);
        }
        this.ˎ.setAdapter(this.ˏ);
        new eiy().ˏ(this.ˎ);
        this.ˎ.setTouchListener(new com.huawei.appgallery.horizontalcard.api.view.BounceHorizontalRecyclerView.b(this) {
            final /* synthetic */ BaseHorizontalModuleCard ॱ;

            {
                this.ॱ = r1;
            }

            public void ˊ() {
                if (1 == this.ॱ.ͺ) {
                    this.ॱ.ˎ(false);
                    this.ॱ.ˏ(this.ॱ.ˎ);
                    this.ॱ.ॱᐝ();
                }
            }
        });
        this.ˎ.ॱ(new n(this) {
            final /* synthetic */ BaseHorizontalModuleCard ˎ;

            {
                this.ˎ = r1;
            }

            public void ˎ(RecyclerView recyclerView, int i) {
                this.ˎ.ͺ = i;
                if (i == 0) {
                    this.ˎ.ˎ(false);
                    this.ˎ.ˏ(recyclerView);
                    this.ˎ.ॱᐝ();
                }
            }

            public void ˊ(RecyclerView recyclerView, int i, int i2) {
                this.ˎ.ˏ(this.ˎ.ͺ);
            }
        });
        this.ˎ.setOnLoadListener(new a());
        this.ʻ = dgm.ˎ((Activity) this.ˎ.getContext());
    }

    public void ˏ(RecyclerView recyclerView) {
    }

    public void ˏ(int i) {
    }

    public void ˏ(CardBean cardBean) {
        super.ˏ(cardBean);
        if (cardBean instanceof BaseHorizontalModuleCardBean) {
            ˎ((BaseHorizontalModuleCardBean) cardBean);
            this.ˊ.ॱ(this.ॱॱ.ﾟ(), this.ॱॱ.ʻᐝ());
            this.ॱ.ॱ(this.ॱॱ.ʽᐝ());
            this.ॱ.ॱ(this.ॱॱ.ʽˋ());
            this.ॱ.ˏ(this.ॱॱ.u_());
            if (CollectCheck.isEmpty(this.ॱॱ.ʻˋ()) || this.ॱॱ.ʻˋ().size() < this.ॱॱ.ʼˊ() || this.ॱॱ.ʾॱ() == 0) {
                this.ॱ.ॱ(false);
            }
            this.ॱ.ॱ().clear();
            if (CollectCheck.isEmpty(this.ॱॱ.ʻˋ())) {
                if (this.ʼ != null) {
                    this.ʼ.setVisibility(8);
                }
                if (this.ˎ != null) {
                    this.ˎ.setVisibility(8);
                }
            } else {
                if (this.ʼ != null) {
                    this.ʼ.setVisibility(0);
                }
                if (this.ˎ != null) {
                    this.ˎ.setVisibility(0);
                }
                for (NormalCardBean normalCardBean : this.ॱॱ.ʻˋ()) {
                    normalCardBean.ˊ(this.ॱॱ.ॱꜞ());
                    normalCardBean.ˋˋ(this.ॱॱ.ॱˉ());
                }
                this.ॱ.ॱ().addAll(this.ॱॱ.ʻˋ());
            }
            ˏॱ();
            this.ˏ.ˊ();
        }
    }

    public void ˊ(chz o_chz, int i) {
        if (o_chz == null) {
            cll.ˎ.ˊ("BaseHorizontalModuleCard", "preSetData dataItem == null");
            return;
        }
        CSSRule ʻ = o_chz.ʻ();
        String ʽ = o_chz.ʽ();
        long j = o_chz.ˏ;
        this.ॱ.ˋ(ʻ);
        this.ॱ.ˋ(ʽ);
        this.ॱ.ˊ(o_chz.ͺ());
        this.ॱ.ॱ(j);
        this.ॱ.ˎ(i);
        this.ॱ.ॱ(o_chz.ˏॱ());
    }

    private void ˏॱ() {
        try {
            Class ॱ = cib.ॱ(Integer.valueOf(this.ॱ.ʻ()));
            if (ॱ == null) {
                cll.ˎ.ˊ("BaseHorizontalModuleCard", "Don't support card type:" + this.ॱ.ʻ());
                return;
            }
            this.ʽ = (NormalCardBean) ॱ.getConstructor(new Class[0]).newInstance(new Object[0]);
            this.ʽ.ʼ(1);
        } catch (Exception e) {
            cll.ˎ.ˊ("BaseHorizontalModuleCard", "createNode error, card type:" + this.ॱ.ʻ() + " , " + e.toString());
        }
    }

    private void ˋॱ() {
        cvt o_clm = new clm();
        o_clm.ˎ(this.ॱ.ˋ());
        o_clm.ˋ(this.ॱ.ˊ());
        o_clm.ॱ(this.ॱॱ.ॱˉ());
        o_clm.ˊ(this.ॱॱ.u_());
        o_clm.ˏ(this.ॱॱ.ʻˊ());
        int ॱ = ccz.ॱ();
        if (this.ˎ != null) {
            ॱ = dgm.ˎ((Activity) this.ˎ.getContext());
        }
        o_clm.setServiceType_(ॱ);
        cfw.ˎ(o_clm, new d(this));
    }

    public BounceHorizontalRecyclerView ʼ() {
        return this.ˎ;
    }

    public clr ॱॱ() {
        return this.ˏ;
    }

    protected void ˎ(BaseHorizontalModuleCardBean<T> baseHorizontalModuleCardBean) {
        this.ॱॱ = baseHorizontalModuleCardBean;
    }

    protected BaseHorizontalModuleCardBean<T> ᐝ() {
        return this.ॱॱ;
    }

    public void ˊ(chy o_chy) {
        this.ˋ = o_chy;
        if (this.ˏ != null) {
            this.ˏ.ˎ(o_chy);
        }
    }

    public boolean ˊ() {
        if (this.ˎ != null) {
            return this.ˎ.ˑ();
        }
        return false;
    }

    private void ॱᐝ() {
        if (ˌ() != null && (ˌ() instanceof BaseHorizontalModuleCardBean)) {
            BaseHorizontalModuleCardBean baseHorizontalModuleCardBean = (BaseHorizontalModuleCardBean) ˌ();
            Object obj = this.ˊ.ॱˎ() == this.ˊ.ˌ() + -1 ? 1 : null;
            int ॱˎ = this.ˊ.ॱˎ();
            int left = ʼ().getLeft();
            int ॱˊ = this.ˊ.ॱˊ();
            if (obj != null) {
                int i;
                if (this.ॱ == null || ॱˎ >= this.ॱ.ॱ().size() || ((NormalCardBean) this.ॱ.ॱ().get(ॱˎ)).ﾞ() != 1) {
                    i = ॱˎ;
                } else {
                    i = ॱˎ - 1;
                }
                baseHorizontalModuleCardBean.ᐝ(i);
                baseHorizontalModuleCardBean.ʽ(left);
                return;
            }
            baseHorizontalModuleCardBean.ʽ(left);
            baseHorizontalModuleCardBean.ᐝ(ॱˊ);
        }
    }

    public void ˎ(boolean z) {
        cll.ˎ.ˋ("BaseHorizontalModuleCard", "caclutExpose");
        this.ˏॱ = System.currentTimeMillis();
        this.ॱˊ = new b(z, this.ʻ);
        this.ॱˊ.ˏ();
    }

    private ArrayList<String> ˎ(int i, int i2) {
        if (this.ॱ == null || this.ॱ.ॱ() == null) {
            return null;
        }
        List arrayList = new ArrayList();
        arrayList.addAll(this.ॱ.ॱ());
        int size = arrayList.size() - 1;
        int ᐝ = this.ॱ.ᐝ();
        ArrayList<String> arrayList2 = new ArrayList();
        while (i <= i2 && i <= size) {
            NormalCardBean normalCardBean = (NormalCardBean) arrayList.get(i);
            if (normalCardBean != null && normalCardBean.ﾞ() != 1 && ((this.ॱˊ == null || !ॱˊ() || this.ॱˊ.ˎ(i)) && !ॱ(arrayList2, i))) {
                int i3 = i * ᐝ;
                StringBuilder stringBuilder = new StringBuilder(256);
                for (int i4 = 0; i4 < ᐝ; i4++) {
                    int i5 = i3 + i4;
                    if (i5 == arrayList.size()) {
                        break;
                    }
                    normalCardBean = (NormalCardBean) arrayList.get(i5);
                    if (normalCardBean != null) {
                        stringBuilder.delete(0, stringBuilder.length());
                        stringBuilder.append(normalCardBean.ॱॱ());
                        stringBuilder.append("#$#");
                        stringBuilder.append(normalCardBean.u_());
                        arrayList2.add(stringBuilder.toString());
                    }
                }
            }
            i++;
        }
        return arrayList2;
    }

    private boolean ॱ(ArrayList<String> arrayList, int i) {
        s ˎ = this.ˎ.ˎ(i);
        if (ˎ instanceof o.clr.a) {
            BaseHorizontalItemCard ˊˊ = ((o.clr.a) ˎ).ˊˊ();
            if (ˊˊ instanceof clk) {
                Collection ॱ = ((clk) ˊˊ).ॱ();
                if (!CollectCheck.isEmpty(ॱ)) {
                    arrayList.addAll(ॱ);
                }
                return true;
            }
        }
        return false;
    }

    public ArrayList<String> ͺ() {
        Collection ˊॱ = ˊॱ();
        if (this.ॱˊ == null) {
            this.ॱˊ = new b(false, this.ʻ);
        }
        int[] ॱ = this.ॱˊ.getVisibleImtePos();
        if (ॱ[0] < 0 || ॱ[1] < 0) {
            return ˊॱ;
        }
        int i = ॱ[0];
        int i2 = ॱ[1];
        if (i == i2 && evt.ˊ(this.ॱˊ.ˏ(i)) < 50) {
            return ˊॱ;
        }
        if (evt.ˊ(this.ॱˊ.ˏ(i)) < 50) {
            i++;
        }
        if (evt.ˊ(this.ॱˊ.ˏ(i2)) < 50) {
            i2--;
        }
        ArrayList<String> ˎ = ˎ(i, i2);
        if (CollectCheck.isEmpty(ˎ)) {
            return ˊॱ;
        }
        if (CollectCheck.isEmpty(ˊॱ)) {
            return ˎ;
        }
        ˎ.addAll(ˊॱ);
        return ˎ;
    }

    public ArrayList<String> ˊॱ() {
        return null;
    }

    public boolean ॱˊ() {
        return false;
    }
}
